#!/usr/bin/env python
# -*- coding:utf-8 -*-

# file:homework6_6.py
# author:wmf
# datetime:2021/4/18 12:13
# software: PyCharm
'''
this is function description
'''


# import module your need


# 六  用面向对象,实现一个学生Python成绩管理系统;
#       学生的信息存储在文件中;学生信息的字段有(班级,学号,姓名, Python成绩)
#       实现对学生信息及成绩的增,删,改,查方法;


class student:
    student_list = []

    def __init__(self, the_class, num, name, score):
        self.student_dict = {"班级": the_class, "学号": num, "姓名": name, "Python成绩": score}

    def insert_info(self):
        student.student_list.append(self.student_dict)
        with open("student.txt", "w", encoding="gbk") as f:
            for x in student.student_list:
                f.write(str(x))
                f.write('\n')

    def del_info(self):  # 根据学号删除信息
        for x in student.student_list:
            student.student_list.remove(x)
        with open("student.txt", "w", encoding="gbk") as f:
            for x in student.student_list:
                f.write(str(x))
                f.write('\n')

    def update_info(self, *new_info):
        for x in self.student_list:
            x[new_info[0]] = new_info[1]
        with open("student.txt", "w", encoding="gbk") as f:
            for x in student.student_list:
                f.write(str(x))
                f.write('\n')

    def find_info(self, num):
        for x in self.student_list:
            return x[num]


stu1 = student("软件1902", "120191080505", "wmf", 100)
stu1.insert_info()
stu2 = student("计算1901", "120191080101", "Tom", 90)
stu2.insert_info()
stu1.del_info()
stu2.update_info("班级", "信安1902")
print(stu2.find_info("学号"))
